﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.TcCommands.TcReloadProduct.CApRealodValidator
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using System.Collections.ObjectModel;
using Tecnomatix.Engineering;
using Tecnomatix.Engineering.Ui;


namespace DnProcessSimulateCommands.TcCommands.TcReloadProduct;

internal class CApRealodValidator : ITxValidator
{
  internal CApRealodValidator()
  {
  }

  internal bool IsValidOperation(ITxObject obj) => obj is ITxTcOperation || obj is TxTcProcess;

  public ITxObject GetObject(string text)
  {
    ITxObject itxObject1 = (ITxObject) null;
    TxObjectList txObjectList = (TxObjectList) null;
    if (text != null)
      txObjectList = TxApplication.ActiveDocument.GetObjectsByName(text);
    if (txObjectList != null && ((Collection<ITxObject>) txObjectList).Count > 0)
    {
      foreach (ITxObject itxObject2 in (Collection<ITxObject>) txObjectList)
      {
        if (this.IsValidObject(itxObject2, out string _))
        {
          itxObject1 = itxObject2;
          break;
        }
      }
    }
    return itxObject1;
  }

  public string GetText(ITxObject obj)
  {
    string text = string.Empty;
    if (obj != null)
      text = obj.Name;
    return text;
  }

  public bool IsValidObject(ITxObject obj, out string errorMessage)
  {
    bool flag1 = false;
    errorMessage = (string) null;
    if (obj == null)
    {
      errorMessage = TcReloadProductStringTable.RELOAD_PRODUCT_INVALID_OBJECT_ERROR;
    }
    else
    {
      bool flag2 = obj is ITxTcOperation || obj is TxTcProcess;
      flag1 = flag2;
      if (!flag2)
        errorMessage = TcReloadProductStringTable.RELOAD_PRODUCT_NOT_A_TXOPERATION_ERROR;
    }
    return flag1;
  }

  public bool IsValidText(string text, out string errorMessage)
  {
    return this.IsValidObject(this.GetObject(text), out errorMessage);
  }
}
